package com.jnc.web.biz.system.service.impl;

import com.jnc.common.constant.SysConstant;
import com.jnc.common.exception.BaseException;
import com.jnc.common.util.convert.ConvertUtil;
import com.jnc.web.biz.system.mapper.DictTypeMapper;
import com.jnc.web.biz.system.model.DictType;
import com.jnc.web.biz.system.service.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: jjn
 * @Date: 2018/11/7
 * @Desc:
 */
@Service
public class DictTypeServiceImpl implements DictTypeService {

    @Autowired
    private DictTypeMapper dictTypeMapper;

    @Override
    public List<DictType> queryDictType(DictType record) {
        return dictTypeMapper.queryDictType(record);
    }

    @Override
    public DictType getDictType(Integer dictTypeId) {
        return dictTypeMapper.getDictType(dictTypeId);
    }

    @Override
    public List<DictType> getNormalDictType() {
        return dictTypeMapper.getNormalDictType();
    }

    @Override
    public List<DictType> getAllDictType() {
        return dictTypeMapper.getAllDictType();
    }

    @Override
    public List<DictType> checkDictType(DictType record) {
        return dictTypeMapper.checkDictType(record);
    }

    @Transactional(value = SysConstant.TX_BASE_NAME)
    @Override
    public int deleteDictType(String ids) {
        List<Integer> list = ConvertUtil.toIntList(ids);
        //校验字典类型是否存在字典数据
        Integer num = dictTypeMapper.checkTypeHasData(list);
        if(num > 0){
            throw new BaseException("删除的字典类型记录中, 存在字典数据未删除, 请先删除字典数据");
        }
        return dictTypeMapper.deleteDictType(list);
    }

    @Transactional(value = SysConstant.TX_BASE_NAME)
    @Override
    public int addDictType(DictType record) {
        return dictTypeMapper.addDictType(record);
    }

    @Transactional(value = SysConstant.TX_BASE_NAME)
    @Override
    public int editDictType(DictType record) {
        return dictTypeMapper.editDictType(record);
    }
}
